package top.superflow.flow.validate

import org.springframework.stereotype.Component
import top.superflow.flow.config.{Config, RouteConfig}
import top.superflow.flow.load.GlobalFlowConfiguration


@Component
class ConfigurationValidationManager{
  
  def isValid(flowConfiguration : GlobalFlowConfiguration) : Boolean = {
    if(flowConfiguration != null){
      iterateToValidate(flowConfiguration.getProcesses)
      iterateToValidate(flowConfiguration.getFlows)
    }
    
    true
  }
  
  private def iterateToValidate(flowElementsInMap : Map[_ , _]){
    if(flowElementsInMap == null) return;
    
    for((group , elementsInGroup) <- flowElementsInMap){
      for((elementKey , element) <- elementsInGroup.asInstanceOf[Map[_,_]]){
        val config = element.asInstanceOf[Config]
        ValidatorFactory.getValidator(config).asInstanceOf[ConfigValidator[Config]].isValid(config)
      }
      
    }
  }
}